﻿<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPages/Dialog.Master" AutoEventWireup="true" CodeBehind="SectorDialogBox.aspx.cs" Inherits="Legazpi.Payroll.Web.PopupBoxes.SectorDialogBox" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
<script type="text/javascript">
    var serviceUrl = '<%=ResolveUrl("~/Webservices/EmployeeWebService.asmx")%>';
    $(document).ready(function () {
        $('#SectorSubmitButton').click(function () {
            if (!$("#dialogForm").valid()) {
                return false;
            }
            var SectorObj = {
                Id: $('#id').val(),
                PositionId: $('#<%=PositionDropdown.ClientID %> option:selected').val(),
                ClientId: $('#ClientId').val(),
                Name: $('#SectorName').val(),
                WorkHours: $('#WorkHours').val(),
                RatePerDay: $('#RatePerDay').val(),
                RatePerHour: $('#RatePerHour').val()
            };
            var json = JSON.stringify({ sectorItem: SectorObj });
            BlockUI.BlockElementLoading("dialog", "Saving...", true, 4);
            $.ajax({
                type: "POST",
                url: serviceUrl + "/AddSector",
                data: json,
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (data) {
                    var response = eval('(' + data.d + ')');
                    if (response.Success) {
                        alert('Saved!');
                        window.location = Client.ClientUrl + '?id=' + response.SectorItem.ClientId;
                    }
                },
                complete: function () {
                    BlockUI.UnBlockElement("dialog");
                }
            });
        });

        $.validator.addMethod('greaterThanZero', function (value, element) {
            return (value > 0);
        }, 'Please select an option.');
        
        $.validator.addMethod('validNumber', function (value, element) {
            var floatRegex = '[-+]?([0-9]*\.[0-9]+|[0-9]+)';
            return (value.match(floatRegex));
        },'Not accept non-numeric');

        $("#dialogForm").validate({
            rules: {
                SectorName: "required",
                WorkHours: {
                    validNumber: true
                },
                RatePerDay: {
                    validNumber: true
                },
                RatePerHour: {
                    validNumber: true
                },
                <%=PositionDropdown.UniqueID %>: {
                    greaterThanZero : true
                }
            },
            messages: {
                SectorName: "Please enter Name",
                <%=PositionDropdown.UniqueID %>: "select position"
            }
        });

    });
</script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="Content" runat="server">
<form id="dialogForm" runat="server">
         <input type="hidden" id="id" value="<%=Model.Id %>" />
         <input type="hidden" id="ClientId" value="<%=Model.ClientId %>" />
            <fieldset class="register">
                <legend>Sector Details</legend>
                <p>
                    <label for="SectorName">Sector Name:</label>
                    <input type="text" id="SectorName" name="SectorName" class="textEntry" value="<%=Model.Name %>" />
                </p>
                <p>
                    <label for="PositionDropdown">Position:</label>
                    <asp:DropDownList ID="PositionDropdown" runat="server">
                    </asp:DropDownList>
                </p>
                <p>
                    <label for="WorkHours">WorkHours:</label>
                    <input type="text" id="WorkHours" name="WorkHours" class="textEntry" value="<%=Model.WorkHours %>" />
                </p>
                <p>
                    <label for="RatePerDay">RatePerDay:</label>
                    <input type="text" id="RatePerDay" name="RatePerDay" class="textEntry" value="<%=Model.RatePerDay %>" />
                </p>
                <p>
                    <label for="RatePerHour">RatePerHour:</label> 
                    <input type="text" id="RatePerHour" name="RatePerHour" class="textEntry" value="<%=Model.RatePerHour %>" />
                </p>
            </fieldset>
            <p class="submitButton">
                <input type="button" id="SectorSubmitButton" value="OK" />
            </p>
</form>
</asp:Content>
